package com.hyz.login.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyz.login.model.Pay;
import com.hyz.login.model.Register;
import com.hyz.login.model.Report;
import com.hyz.login.service.PayService;
import com.hyz.login.service.RegisterService;
import com.hyz.login.service.ReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwq
 * @since 2022-11-28
 */
@Controller
@RequestMapping("/register")
public class RegisterController {
    Logger logger = LoggerFactory.getLogger(Register.class);

    @Autowired
    private RegisterService registerService;
    @Autowired
    private ReportService reportService;
    @Autowired
    private PayService payService;

    @RequestMapping("/selreg")
    @ResponseBody
    public String adminFindPage(@RequestParam(required = false,defaultValue = "")String userName,
                                @RequestParam(required = false,defaultValue = "1")Integer page,
                                @RequestParam(required = false,defaultValue = "5")Integer limit){
        IPage<Register> iPage = registerService.adminFindPage(userName, page, limit);
        return "{\"msg\":\"\",\"code\":0,\"count\":"+iPage.getTotal()+",\"data\":"+ JSON.toJSONString(iPage.getRecords())+"}";
    }

    @RequestMapping("/updKe")
    @ResponseBody
    public String updKe(Integer registerid,Integer departmentId,Integer doctorId,Integer bedId){
        int ret = registerService.modifyByRegId(registerid, departmentId, doctorId, bedId);
        if (ret>0){
            return "转科成功";
        }
        return "转科失败";
    }

    @RequestMapping("/addRegister")
    @ResponseBody
    public String addRegister(Register register,Integer reportId){
        int ret = registerService.addRegister(register);
        reportService.modifyRegById(reportId);
        if (ret>0){
            return "入院成功";
        }
        return "入院失败";
    }

}

